import { useEffect ,useState } from 'react'

const Simulation = () => {

const [num,setNum] = useState(1)



  console.log('进入页面了')


  //   模拟componentDidMount
  useEffect(() => {
    console.log(111)
  }, [])

  //   模拟componentDidUpdate
  useEffect(() => {
   console.log('页面更新了',num);
  })

  //   模拟componentWillUnmount
  useEffect(() => {
return()=>{
    console.log('页面将要卸载了');
}
   },[] )
 




  const add=()=>{
    setNum(num+1)
  }

  return (
    <>
      <div></div>
      <h1>{num}</h1>
      <button onClick={add}>数量加1</button>
    </>
  )
}

export default Simulation
